<!DOCTYPE html>
<html>
<head>
    <title>编辑科普文章 - 垃圾分类系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }
        
        .container {
            max-width: 800px;
            margin: 0 auto;
        }
        
        .header {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            padding: 20px 30px;
            margin-bottom: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
        }
        
        .header h1 {
            color: #2d3748;
            font-size: 28px;
            font-weight: 700;
            display: flex;
            align-items: center;
            gap: 12px;
        }
        
        .header-actions {
            display: flex;
            gap: 12px;
            flex-wrap: wrap;
        }
        
        .btn {
            padding: 10px 20px;
            border: none;
            border-radius: 10px;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            text-decoration: none;
            transition: all 0.3s ease;
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }
        
        .btn-primary {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
        
        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(102, 126, 234, 0.3);
        }
        
        .btn-success {
            background: linear-gradient(135deg, #10b981 0%, #059669 100%);
            color: white;
        }
        
        .btn-success:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(16, 185, 129, 0.3);
        }
        
        .btn-secondary {
            background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
            color: white;
        }
        
        .btn-secondary:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(107, 114, 128, 0.3);
        }
        
        .btn-danger {
            background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
            color: white;
        }
        
        .btn-danger:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(239, 68, 68, 0.3);
        }
        
        .page-title {
            color: white;
            font-size: 32px;
            font-weight: 700;
            margin-bottom: 30px;
            text-align: center;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        
        .form-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            padding: 40px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            animation: slideUp 0.6s ease-out;
        }
        
        @keyframes slideUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .form-group {
            margin-bottom: 25px;
        }
        
        .form-label {
            display: block;
            margin-bottom: 8px;
            font-weight: 600;
            color: #374151;
            font-size: 14px;
        }
        
        .form-input,
        .form-select,
        .form-textarea {
            width: 100%;
            padding: 12px 16px;
            border: 2px solid #e5e7eb;
            border-radius: 12px;
            font-size: 16px;
            transition: all 0.3s ease;
            background: white;
        }
        
        .form-input:focus,
        .form-select:focus,
        .form-textarea:focus {
            outline: none;
            border-color: #667eea;
            box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
        }
        
        .form-textarea {
            min-height: 200px;
            resize: vertical;
            font-family: inherit;
        }
        
        .form-actions {
            display: flex;
            gap: 16px;
            justify-content: center;
            margin-top: 30px;
        }
        
        .flash-messages {
            margin-bottom: 20px;
        }
        
        .flash-message {
            padding: 12px 20px;
            border-radius: 10px;
            margin-bottom: 10px;
            font-weight: 500;
        }
        
        .flash-success {
            background: linear-gradient(135deg, #ecfdf5 0%, #d1fae5 100%);
            color: #065f46;
            border: 1px solid #10b981;
        }
        
        .flash-error {
            background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
            color: #7f1d1d;
            border: 1px solid #ef4444;
        }
        
        .form-help {
            font-size: 12px;
            color: #6b7280;
            margin-top: 4px;
        }
        
        .required {
            color: #ef4444;
        }
        
        .article-info {
            background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
            border-radius: 12px;
            padding: 16px;
            margin-bottom: 25px;
            border: 1px solid #e5e7eb;
        }
        
        .article-info h3 {
            color: #374151;
            margin-bottom: 8px;
            font-size: 16px;
        }
        
        .article-meta {
            display: flex;
            gap: 20px;
            flex-wrap: wrap;
            font-size: 14px;
            color: #6b7280;
        }
        
        @media (max-width: 768px) {
            .header {
                flex-direction: column;
                gap: 16px;
                text-align: center;
            }
            
            .header-actions {
                justify-content: center;
            }
            
            .page-title {
                font-size: 24px;
            }
            
            .form-card {
                padding: 20px;
            }
            
            .form-actions {
                flex-direction: column;
            }
            
            .article-meta {
                flex-direction: column;
                gap: 8px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header class="header">
            <h1>✏️ 编辑科普文章</h1>
            <div class="header-actions">
                <a href="/knowledge/{{ article.id }}" class="btn btn-primary" target="_blank">👁️ 预览</a>
                <a href="/admin/knowledge" class="btn btn-secondary">⬅️ 返回列表</a>
            </div>
        </header>
        
        <h1 class="page-title">✏️ 编辑科普文章</h1>
        
        <div class="form-card">
            {% with messages = get_flashed_messages(with_categories=true) %}
                {% if messages %}
                    <div class="flash-messages">
                        {% for category, message in messages %}
                            <div class="flash-message flash-{{ category }}">
                                {{ message }}
                            </div>
                        {% endfor %}
                    </div>
                {% endif %}
            {% endwith %}
            
            <div class="article-info">
                <h3>📊 文章信息</h3>
                <div class="article-meta">
                    <span>👁️ 浏览次数：{{ article.view_count }}</span>
                    <span>📅 创建时间：{{ article.created_at.strftime('%Y-%m-%d %H:%M') }}</span>
                    <span>🔄 更新时间：{{ article.updated_at.strftime('%Y-%m-%d %H:%M') }}</span>
                    <span>👤 作者：{{ article.author }}</span>
                </div>
            </div>
            
            <form method="POST">
                <div class="form-group">
                    <label for="title" class="form-label">文章标题 <span class="required">*</span></label>
                    <input type="text" id="title" name="title" class="form-input" required 
                           placeholder="请输入文章标题" value="{{ article.title }}">
                    <div class="form-help">请输入简洁明了的文章标题</div>
                </div>
                
                <div class="form-group">
                    <label for="category" class="form-label">文章分类 <span class="required">*</span></label>
                    <select id="category" name="category" class="form-select" required>
                        <option value="">请选择分类</option>
                        <option value="可回收垃圾" {{ 'selected' if article.category == '可回收垃圾' }}>♻️ 可回收垃圾</option>
                        <option value="有害垃圾" {{ 'selected' if article.category == '有害垃圾' }}>☠️ 有害垃圾</option>
                        <option value="厨余垃圾" {{ 'selected' if article.category == '厨余垃圾' }}>🍎 厨余垃圾</option>
                        <option value="其他垃圾" {{ 'selected' if article.category == '其他垃圾' }}>🗑️ 其他垃圾</option>
                        <option value="垃圾分类知识" {{ 'selected' if article.category == '垃圾分类知识' }}>📚 垃圾分类知识</option>
                        <option value="环保知识" {{ 'selected' if article.category == '环保知识' }}>🌱 环保知识</option>
                    </select>
                    <div class="form-help">选择文章所属的分类</div>
                </div>
                
                <div class="form-group">
                    <label for="content" class="form-label">文章内容 <span class="required">*</span></label>
                    <textarea id="content" name="content" class="form-textarea" required 
                              placeholder="请输入文章内容，支持换行和基本格式">{{ article.content }}</textarea>
                    <div class="form-help">请输入详细的文章内容，可以包含多个段落</div>
                </div>
                
                <div class="form-group">
                    <label for="image_url" class="form-label">配图链接</label>
                    <input type="url" id="image_url" name="image_url" class="form-input" 
                           placeholder="https://example.com/image.jpg" value="{{ article.image_url or '' }}">
                    <div class="form-help">可选：添加文章配图的网络链接</div>
                </div>
                
                <div class="form-actions">
                    <button type="submit" class="btn btn-success">💾 保存修改</button>
                    <a href="/admin/knowledge" class="btn btn-secondary">❌ 取消</a>
                    <a href="/admin/knowledge/delete/{{ article.id }}" class="btn btn-danger" 
                       onclick="return confirm('确定要删除这篇文章吗？此操作不可撤销！')">🗑️ 删除文章</a>
                </div>
            </form>
        </div>
    </div>
</body>
</html>